package code.simulation.graficinterface;

import java.util.Random;

import code.mobility.Position;
import code.wrtp.Station;

public class Tester {

	private Random generator;
	private String subNet;
	private short receiverPort;
	private Station[] stations;

	public Tester() {
		generator = new Random();
		subNet = "127.168.2.";
		receiverPort = 8888;
	}

	private Position generatePosition(double fator, double limitanteInferior) {
		double x, y, z;
		x = generator.nextDouble() * fator + limitanteInferior;
		y = generator.nextDouble() * fator + limitanteInferior;
		z = generator.nextDouble() * fator + limitanteInferior;

		return (new Position(x, y, z));
	}

	private double generateSpeed(double fator, double limitanteInferior) {
		return generator.nextDouble() * fator + limitanteInferior;
	}

	private double generateEnergy(double fator, double limitanteInferior) {
		return generator.nextDouble() * fator + limitanteInferior;
	}

	public void generateStationAndTest(int nodeNumber) {

		Position position;
		stations = new Station[nodeNumber];
		for (short id = 0; id < nodeNumber; id++) {
			position = generatePosition(50, 0);
			stations[id] = new Station((short) (id + 1), position,
					generateSpeed(10, 0), generateEnergy(12, 0), subNet,
					receiverPort);
			stations[id].startThread();
		}
	}

	public void finalizeTest(int nodeNumber) {
		for (short id = 0; id < nodeNumber; id++) {
			stations[id].stopThread();
		}
	}

	public static void main(String[] args) {
		int nodeNumber = 2;
		Tester tester = new Tester();
		tester.generateStationAndTest(nodeNumber);
		tester.finalizeTest(nodeNumber);
	}
}
